package com.sc.nft.admin.controller;

import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dto.IdRequest;
import com.sc.nft.dto.MallGoodsLabelItemDTO;
import com.sc.nft.dto.MallGoodsLabelSaveGoodsDTO;
import com.sc.nft.entity.MallGoodsLabel;
import com.sc.nft.entity.dto.MallGoodsLabelDTO;
import com.sc.nft.entity.dto.MallGoodsLabelPageDTO;
import com.sc.nft.entity.vo.EditActivityCouponsVO;
import com.sc.nft.entity.vo.MallGoodsLabelItemPageVO;
import com.sc.nft.entity.vo.MallGoodsLabelPageVO;
import com.sc.nft.entity.vo.MallGoodsLabelVO;
import com.sc.nft.service.MallGoodsLabelService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/mall/goods/label")
@Api(tags = "标签管理")
public class MallGoodsLabelController {
    /**
     * 服务对象
     */
    private final MallGoodsLabelService mallGoodsLabelService;

    @ApiOperation(value = "添加标签", notes = "添加标签", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
//    @SysMemberLogin
    public Result create(@Valid @RequestBody MallGoodsLabelDTO goodsLabelDTO) {
        mallGoodsLabelService.create(goodsLabelDTO);
        return Result.success();
    }



    @ApiOperation(value = "编辑标签", notes = "编辑标签", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
//    @SysMemberLogin
    public Result update(@Valid @RequestBody MallGoodsLabelDTO goodsLabelDTO) {
        mallGoodsLabelService.update(goodsLabelDTO);
        return Result.success();
    }

    @ApiOperation(value = "标签详情", notes = "标签详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/details", produces = MediaType.APPLICATION_JSON_VALUE)
//    @SysMemberLogin
    public Result<MallGoodsLabelVO> details(@Valid @RequestBody IdRequest idRequest) {
        return Result.success(mallGoodsLabelService.details(idRequest));
    }

    @ApiOperation(value = "标签开启", notes = "标签开启", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/enable", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result enable(@Valid @RequestBody IdRequest idRequest) {
        mallGoodsLabelService.enable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "标签关闭", notes = "标签关闭", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/disable", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result disable(@Valid @RequestBody IdRequest idRequest) {
        mallGoodsLabelService.disable(idRequest.getId());
        return Result.success();
    }


    @ApiOperation(value = "标签列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<MallGoodsLabelPageVO> page(@Valid @RequestBody MallGoodsLabelPageDTO mallGoodsLabelPageDTO) {
        return  PageResult.success(mallGoodsLabelService.page(mallGoodsLabelPageDTO));
    }

    @ApiOperation(value = "标签删除", notes = "标签删除", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/remove", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result remove(@Valid @RequestBody IdRequest idRequest) {
        mallGoodsLabelService.remove(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "标签关联的商品", notes = "关联的商品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/goodsPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<MallGoodsLabelItemPageVO>> goodsPage(@Valid @RequestBody IdRequest idRequest) {
        return Result.success(mallGoodsLabelService.goodsPage(idRequest.getId()));
    }

    @ApiOperation(value = "标签保存关联的商品", notes = "保存关联的商品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveGoods", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<MallGoodsLabelItemPageVO>> saveGoods(@Valid @RequestBody MallGoodsLabelSaveGoodsDTO saveGoodsDTO) {
        mallGoodsLabelService.saveGoods(saveGoodsDTO);
        return Result.success();
    }


}
